package com.Domain;

import java.util.ArrayList;
import java.util.List;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;

/**
 *
 * @author faust
 */
@Root (name="Layer")
public class Layer {

	@Element (name="markerId")
    private int markerId;
	@ElementList (name="models")
    private List<Model> models;
	@Element (name="name")
    private String name;
	@Element (name="width")
    private float width;
	
	private int selectedModel;


    public Layer() {
        markerId = -1;
        name = "";
        width = -1;
        models = new ArrayList<Model>();
        selectedModel = 0;
    }

    public Layer(int markerId, String name, float width, List<Model> models) {
        this.markerId = markerId;
        this.name = name;
        this.width = width;
        this.models = new ArrayList<Model>(models);
        this.selectedModel = 0;
    }


    public int getMarkerId() {
        return markerId;
    }

    public void setMarkerId(int markerId) {
        this.markerId = markerId;
    }

    public List<Model> getModels() {
        return models;
    }

    public void setModels(List<Model> models) {
        this.models = models;
    }
    
    public int getModelCount() {
    	return models.size();
    }

    public Model getModel(int i) {
        return models.get(i);
    }

    public void removeModel(int i) {
        models.remove(i);
    }

    public void addModel(Model m) {
        models.add(m);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getWidth() {
        return width;
    }

    public void setWidth(float width) {
        this.width = width;
    }
    
    /*public float getSelectedScaleFactor() {
		return this.models.get(getSelectedModel()).getScaleFactor();
	}

	public void setSelectedScaleFactor(float scaleFactor) {
		this.models.get(getSelectedModel()).setScaleFactor(scaleFactor);
	}
	
	public float getSelectedTranslateX() {
		return this.models.get(getSelectedModel()).getTranslateX();
	}
	
	public float getSelectedTranslateY() {
		return this.models.get(getSelectedModel()).getTranslateY();
	}
	
	public void setSelectedTranslate(float incX, float incY) {
		this.models.get(getSelectedModel()).setTranslate(incX, incY);
	}
    
    public int getSelectedModel() {
    	return this.selectedModel;
    }
    
    public void setSelectedModel(int selectedModel) {
    	this.selectedModel = selectedModel;
    }
    
    public void selectNextModel() {
    	this.selectedModel = (this.selectedModel + 1)%this.models.size();
    }
    
    public void selectPreviousModel() {
    	this.selectedModel = (this.selectedModel - 1);
    	if (this.selectedModel < 0) this.selectedModel = this.models.size()-1;
    }*/
    
    /** Load the model data of every Model on this layer*/
    public void load() {
    	for (Model m: models) m.load();
    }

    @Override
    public String toString() {

        StringBuilder result = new StringBuilder();
        String NEW_LINE = System.getProperty("line.separator");

        result.append(NEW_LINE + "  Layer {" + NEW_LINE);
        result.append("   - MarkerId: " + markerId + NEW_LINE);
        result.append("   - Name: " + name + NEW_LINE);
        result.append("   - width: " + width + NEW_LINE);
        result.append("   - models: " + models.toString() + NEW_LINE);
        result.append("  }");

        return result.toString();
    }

}
